
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 08/18/2014 21:39:12
-- Generated from EDMX file: G:\CTYWX\Microhard.Plat.CompanyChargingMng\DataAccess\ChargingDB.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [C6];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_EMPLOYEE_REFERENCE_COMPANY]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Employee] DROP CONSTRAINT [FK_EMPLOYEE_REFERENCE_COMPANY];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[Company]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Company];
GO
IF OBJECT_ID(N'[dbo].[Employee]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Employee];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Companies'
CREATE TABLE [dbo].[Companies] (
    [CompanyID] uniqueidentifier  NOT NULL,
    [Com_CompanyID] uniqueidentifier  NULL,
    [Name] nvarchar(50)  NULL,
    [CompanyType] int  NULL,
    [Status] bit  NULL
);
GO

-- Creating table 'Employees'
CREATE TABLE [dbo].[Employees] (
    [EmployeeID] uniqueidentifier  NOT NULL,
    [CompanyID] uniqueidentifier  NULL,
    [CreateTime] datetime  NULL,
    [Range] int  NULL,
    [Name] nvarchar(50)  NULL,
    [Cellphone] nvarchar(50)  NULL,
    [WeixinOpenID] nvarchar(50)  NULL,
    [QQMail] nvarchar(50)  NULL,
    [UserName] nvarchar(50)  NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [CompanyID] in table 'Companies'
ALTER TABLE [dbo].[Companies]
ADD CONSTRAINT [PK_Companies]
    PRIMARY KEY CLUSTERED ([CompanyID] ASC);
GO

-- Creating primary key on [EmployeeID] in table 'Employees'
ALTER TABLE [dbo].[Employees]
ADD CONSTRAINT [PK_Employees]
    PRIMARY KEY CLUSTERED ([EmployeeID] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [CompanyID] in table 'Employees'
ALTER TABLE [dbo].[Employees]
ADD CONSTRAINT [FK_EMPLOYEE_REFERENCE_COMPANY]
    FOREIGN KEY ([CompanyID])
    REFERENCES [dbo].[Companies]
        ([CompanyID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_EMPLOYEE_REFERENCE_COMPANY'
CREATE INDEX [IX_FK_EMPLOYEE_REFERENCE_COMPANY]
ON [dbo].[Employees]
    ([CompanyID]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------